package lion.framework.core.task.anno;

import java.lang.annotation.Annotation;

import org.apache.commons.lang.StringUtils;

import lion.dev.lang.MapJ;
import lion.framework.core.anno.AnnotationProcessorManager;
import lion.framework.core.anno.IAnnotationProcessor;
import lion.framework.core.task.AutoTaskManager;
import lion.framework.core.task.ITaskTimerRule;

//@AnnoProcessor(TimerRule.class)
public class TimerRuleAnnoProcessor implements IAnnotationProcessor {

	@SuppressWarnings("unchecked")
	@Override
	public void processe(MapJ ctx, Annotation anno) throws Exception {

		Class<?> clazz = ctx.getE(AnnotationProcessorManager.ANNO_CONTEXT_CLASS);

		if (!ITaskTimerRule.class.isAssignableFrom(clazz)) { return; }

		TimerRule tr = (TimerRule) anno;
		String val = tr.value();
		if (StringUtils.isBlank(val)) { return; }
		AutoTaskManager.registTimerRuleType(val, (Class<? extends ITaskTimerRule>) clazz);
	}
}
